#include "Joystick.h"

//#define JOYSTICK_TYPE_JOYSTICK             0x04
//#define JOYSTICK_TYPE_GAMEPAD              0x05
//#define JOYSTICK_TYPE_MULTI_AXIS           0x08

Joystick_ Joystick(
  JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_MULTI_AXIS, 
  3, // Button Count
  0, // Hat Switch Count
  true, //X
  true, //Y
  false, //Z
  false, //Rx
  false, //Ry
  false, //Rz
  true, //rudder
  true, //throttle
  true, //accelerator
  false, //brake
  true//steering
);

void setup() {
  //Serial.begin(9600);
  Joystick.setXAxisRange(110, 910);
  Joystick.setSteeringRange(110, 910);
  
  Joystick.setYAxisRange(110, 900);
  
  Joystick.setThrottleRange(95, 900);
  Joystick.setAcceleratorRange(95, 900);
  
  Joystick.setRudderRange(110, 900);

  //if (testAutoSendMode)
  //{
  //Joystick.begin();
  //}
  //else
  //{
  Joystick.begin(false);
  //}
}

void loop() {

  int a0 = analogRead(A0);
  //Serial.print("a0:");
  //Serial.println(a0);
  Joystick.setYAxis(a0);// 110~900
  //if(a0<200){
  //  Joystick.setButton(1, 1);
  //}else{
  //  Joystick.setButton(1, 0);
  //}
  //if(a0>800){
  //  Joystick.setButton(2, 1);
  //}else{
  //  Joystick.setButton(2, 0);
  //}

  int a1 = analogRead(A1);
  //Serial.print("a1:");
  //Serial.println(a1);
  Joystick.setRudder(a1);// 110~900

  int a2 = analogRead(A2);
  a2 = 1024 - a2;
  //Serial.print("a2:");
  //Serial.println(a2);
  Joystick.setThrottle(a2);//95~900
  Joystick.setAccelerator(a2);
  
  int a3 = analogRead(A3);
  //Serial.print("a3:");
  //Serial.println(a3);
  Joystick.setXAxis(a3);// 110~910
  Joystick.setSteering(a3);// 110~900

  int d2 = !digitalRead(2);
  //Serial.print("d2:");
  //Serial.println(d2);

  Joystick.setButton(0, d2);
  
  
  Joystick.sendState();
  
  delay(100);
}

